How to use the CSS file?

CSS (Cascading Style Sheets) can be applied in three main ways: inline, internal (or embedded), and external. Here’s a brief explanation of each along with examples:

1. Inline CSS: Inline CSS is applied directly within the HTML tags using the style attribute. This method is suitable for applying styles to individual element.

CSS




<p style="color: blue; font-size: 16px;">This is a paragraph with inline styles.</p>


2. Internal (Embedded) CSS: Internal or embedded CSS is placed within the HTML document, typically in the head section, using the <style> tag. This method is useful when applying styles to a specific page.

HTML




<!DOCTYPE html>
<html>
<head>
  <style>
    p {
      color: green;
      font-size: 18px;
    }
  </style>
</head>
<body>
  <p>This is a paragraph with internal styles.</p>
</body>
</html>


External CSS: External CSS is stored in a separate CSS file and linked to the HTML document. This method allows for the separation of style and content, making it easier to maintain and apply consistent styles across multiple pages.

HTML




<!-- HTML document linking to the external CSS file -->
<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
  <p>This is a paragraph with external styles.</p>
</body>
</html>


CSS




/* File: styles.css */
/* styles.css */
p {
  color: red;
  font-size: 20px;
}


CSS File Format | .css Extension

CSS, or Cascading Style Sheets, is a style sheet language used in web development to describe the presentation and formatting of a document written in HTML or XML. CSS is essential for separating the content of a web page from its visual representation, allowing web developers to control the layout, colors, fonts, and other stylistic aspects of their web pages.

Table of Content

  • Brief History
  • Why you should use CSS?
  • How CSS Solved a Big Problem?
  • How to use the CSS file?
  • Example
  • Conclusion

Similar Reads

Brief History

CSS, or Cascading Style Sheets, has undergone a transformative journey since its inception in 1996. Initially designed to separate the presentation layer from HTML, CSS1 laid the foundation. CSS2, introduced in 1998, expanded capabilities, while CSS 2.1 (2011) stabilized the specification. CSS3, a modular collection of features, brought advanced selectors, media queries, layout models like Flexbox and Grid, transitions, and animations. It played a pivotal role in responsive web design, allowing websites to adapt to diverse devices...

Why you should use CSS?

Here are some of the major reasons why we should use the CSS:...

How CSS Solved a Big Problem?

The Html was never build to write designing part of the website , its only purpose was to write the structure of the website. Problem was that for large project it was difficult for the developer to work because the HTML files were getting more and more complex to solve this problem CSS was introduce which separate the designing part from the html files make easier for the developer to work on the complex projects....

How to use the CSS file?

CSS (Cascading Style Sheets) can be applied in three main ways: inline, internal (or embedded), and external. Here’s a brief explanation of each along with examples:...

Example:

...

Conclusion

...