Introduction and Basics of CSS

What is CSS3?

CSS3, which stands for Cascading Style Sheets Level 3, is a powerful and versatile stylesheet language used to describe the presentation and styling of web documents written in HTML and XML. It allows you to control the visual appearance of elements on a web page, making it an essential tool for web design and layout. CSS3 introduces advanced features and enhancements that enable more sophisticated and dynamic styling possibilities.

Styling HTML Elements with Inline and Internal CSS:

CSS3 offers various methods for styling HTML elements, providing flexibility and control over the design of your web pages.

Inline CSS: Inline CSS involves applying styles directly within HTML tags using the style attribute. This method is useful for applying unique styles to specific elements.

html code

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

Internal CSS: Internal CSS involves placing CSS rules within the <style> tag in the <head> section of an HTML document. This method is suitable for applying consistent styles to multiple elements within the same document.

html code

<head> <style> p { color: red; font-size: 18px; } </style> </head> <body> <p>This is another styled paragraph.</p> </body>

Creating and Linking External CSS Files:

External CSS is a widely used approach that separates style rules from HTML content, promoting better organization and maintainability.

Creating an External CSS File:

  1. Create a new plain text file with a .css extension (e.g., styles.css).
  2. Write your CSS rules within this file.

css code

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

Linking an External CSS File: In your HTML document’s <head> section, use the <link> tag to link the external CSS file.

html code

<head> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <p>This paragraph is styled externally.</p> </body>

By understanding CSS3, styling HTML elements using different methods, and linking external CSS files, you’ll have the foundation to create visually appealing and consistent designs for your web pages.

Scroll to Top