Home > Web Front-end > HTML Tutorial > How to put css in html file

How to put css in html file

藏色散人
Release: 2023-01-03 09:30:57
Original
29818 people have browsed it

Methods to put css in html files: 1. Add CSS directly to the style attribute in the HTML tag; 2. Write CSS under the style tag in the HTML header; 3. Use the head tag to introduce external CSS files; 4. Use CSS rules to introduce external CSS files.

How to put css in html file

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, DELL G3 computer

How to introduce CSS into HTML

There are 4 ways to introduce CSS in HTML. Two of them are to add CSS code directly in the HTML file, and the other two are to introduce external CSS files. Let’s take a look at these methods and their advantages and disadvantages.

Inline method

The inline method refers to adding CSS directly to the style attribute in the HTML tag.

Example:

<div style="background: red"></div>
Copy after login

This is usually a bad way of writing, it can only change the style of the current tag. If you want multiple

to have the same style, you have to Repeatedly add the same style to each
. If you want to modify a style, you have to modify the code in all styles. Obviously, introducing CSS code inline will cause the HTML code to become verbose and make the web page difficult to maintain.

Embedding method

The embedding method refers to writing CSS code under the