Connecting CSS to HTML
Swipe to show menu
How CSS Is Added to HTML
There are three ways to apply CSS to an HTML document:
- Inline styles;
- Embedded style sheets;
- External style sheets.
Each method works differently and is used in different situations.
Inline Styles
Inline styles are written directly inside an HTML element using the style attribute.
Example:
index.html
This style applies only to this specific element.
Inline styles are quick to use, but they are not reusable and are difficult to manage in larger projects.
Embedded Style Sheet
An embedded style sheet is written inside <style> tags in the <head> section of an HTML document.
Example:
index.html
This method applies styles to the entire page, but only within this single HTML file.
It is useful for small or standalone pages.
External Style Sheet
External CSS stores styles in a separate .css file and connects it to HTML using the <link> tag.
Example:
index.html
styles.css
This method allows styles to be reused across multiple pages.
It is the preferred and most scalable approach for real projects.
Inline styles: applied directly to elements, but not reusable.
Embedded style sheet: applied inside the <head>, affects only one page.
External style sheet: stored in a separate .css file, reusable and recommended for most projects.
In this course, we will primarily use external style sheets.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat