Account
Categories

How to Add CSS to HTML


When you create a webpage, you need to style it — and for that, CSS is added to HTML. There are three clean ways to do this: 1. Inline CSS When you directly add styling inside an HTML tag using the style attribute — whether it’s one line or multiple — that’s called Inline CSS. It’s like giving instant instructions to just that one element, right there, without using any separate file or extra class. Syntax(in HTML file only): Example:

This is an inline styled paragraph.

2. Internal CSS When you place your CSS directly inside a Example:

Hello World

Note: Best when you have just one page and want to control all the styles from one central file or section. 3. External CSS When you keep all your CSS in a separate .css file and connect it to your HTML using the tag — that’s called **External CSS Syntax in HTML file: Syntax in CSS file (style.css): selector { property: value; } Example

This heading uses external CSS.

Example (style.css file): h2 { color: red; font-family: Arial; } Note: Best for full websites or when the same styles are needed on multiple pages.