CSS, also known as Cascading Style Sheets, is a game-changing language that revolutionized the web design process. With its simple design, CSS makes it easy to enhance the presentation of web pages, by applying styles independently of the HTML that makes up each page. Essentially, CSS is responsible for the aesthetic appeal of a website, dictating everything from font choice to color scheme and spacing. With this language, developers and designers can create visually appealing websites that truly stand out.
Unlike HTML, which uses tags, CSS uses rulesets. Despite its powerful control over the presentation of an HTML document, CSS is easy to learn and understand. In fact, it offers many benefits that make it a highly practical choice for web development:
CSS3 is the latest version of CSS, which offers even more advanced features and increased efficiency. With CSS3, developers can create highly personalized and user-friendly websites that truly stand out from the crowd.
A CSS consists of style rules that are interpreted by the browser and then applied to the corresponding elements in your document. These style rules are made up of three essential parts, each of which contributes to the overall aesthetic of your website:
Syntax:
selector { property: value }
CSS declaration always ends with a semicolon, and declaration blocks are surrounded by curly braces. Example : In the following example all p elements will be center-aligned, with a blue text color:
p {
color: blue;
text-align: center;
}
There are three types of CSS:
Inline CSS is used to apply styling to a single HTML element. This type of CSS is added directly to the HTML element using the "style" attribute. Inline CSS is easy to use and can be added quickly, but it should be used sparingly as it can make the HTML code cluttered and difficult to read. Inline CSS is typically used for small changes, such as changing the color of a single element.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Inline CSS</title>
</head>
<body>
<p style = "color:#009900; font-size:50px;
font-style:italic; text-align:center;">
GeeksForGeeks
</p>
</body>
</html>
Internal CSS is used to apply styling to a single HTML document. This type of CSS is added to the head section of the HTML document using the "style" tag. Internal CSS is more organized than inline CSS, but it can still be difficult to maintain if the HTML document is large. Internal CSS is typically used for medium-sized web pages, as it allows for more complex styling than inline CSS. Internal style sheets increase page load times, that’s why many developers avoid such practice
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: black;
}
h1 {
color: red;
padding: 50px;
}
</style>
</head>
<body>
<h2>CSS types</h2>
<p>Cascading Style sheet types: inline, external and internal</p>
</body>
</html>
External CSS contains a separate CSS file that contains only style properties with the help of tag attributes (For example class, id, heading, … etc). CSS property is written in a separate file with a .css extension and should be linked to the HTML document using a link tag. This means that for each element, style can be set only once and that will be applied across web pages. External CSS is the most organized type of CSS, as it allows for easy maintenance and updating of the styling across multiple HTML documents. External CSS is typically used for large web pages or websites.
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>This text is styled by the 'styles.css' file.</p>
</body>
In conclusion, Cascading Style Sheets (CSS) is a language that revolutionized the web design process by making it easier to enhance the presentation of web pages by applying styles independently of the HTML that makes up each page. With its powerful control over the presentation of an HTML document, CSS is easy to learn and understand, offers many benefits such as time-saving, easy maintenance, SEO-friendly, advanced styling features, and offline browsing. CSS3, the latest version of CSS, offers even more advanced features and increased efficiency, enabling developers to create highly personalized and user-friendly websites that truly stand out from the crowd. CSS syntax is made up of style rules that consist of selectors, properties, and values. CSS also has three types: inline, internal or embedded, and external, each with its own unique advantages and disadvantages. By understanding CSS and its various types, developers and designers can create visually appealing websites that are easy to maintain and update.
Top Tutorials
Related Articles