Sunday, 25 October 2026

Cascading Style Sheets in HTML

What is CSS and Why Cascading?

CSS is an old but gold technology, where styles can be defined in a central style sheet and used across multiple web pages. Cascading refers to the hierarchical logic implicit in the style sheet. A style applied to a parent element will also apply to all child elements of the parent.  For example, if body text of a paragraph is blue, any other elements in that paragraph also inherit blue unless explicitly overriden.

Alternatives to Separate Style Sheet (Inline CSS using style attribute)

A separate style sheet file is the preferred option for maintainability. However there are other ways of using CSS within a specific file. For example, an inline CSS can be used to apply a unique style to a single HTML element, using the style attribute.

<h1 style="color:blue;">Blue heading</h1>
<p style="color:red;">Red paragraph</p>

No comments: