Welcome to CSS (Cascading Style Sheets), a pivotal tool for configuring the aesthetics of a website. In this lesson, we will delve into the basics of CSS and learn how to apply styles to HTML elements. By the end of this exploration, you will be capable of crafting essential styles and applying them to HTML elements using various methods. Let's dive in!
CSS lends style to an HTML structure. A CSS rule consists of a selector and a declaration block. In this instance, our aim is to turn an HTML heading blue:
In this snippet, "h1" is the selector, while "color: blue;" is the declaration block.
CSS can be implemented in three distinct ways — Inline, Internal, and External.
Inline CSS allows us to style directly onto HTML elements using the style attribute. It's akin to hand-painting each word on a page:
While perfect for quick fixes, combining many inline styles can clutter our HTML.
Internal CSS gathers all styles in a <style> tag within the HTML's <head>, creating a uniform look for the entire page:
This method ensures all paragraphs adopt the same style, bringing consistency across the page.
For larger projects spanning many HTML pages, external CSS stores styles in a separate .css file, which is linked to each HTML page. This acts like a uniform for an entire fleet of spaceships:
HTML page:
CSS page:
All HTML pages linked to the CSS file will display paragraph text in blue.
