tag in the tag of HTML; 3. External style sheets: Use the tag to create and link external CSS files."/> tag in the tag of HTML; 3. External style sheets: Use the tag to create and link external CSS files.">
search
HomeWeb Front-endCSS TutorialHow to embed css into html?

How to embed css into html?

May 18, 2019 pm 04:38 PM
csshtml

How to embed css into html?

There are three main ways to embed CSS styles into html:

1. Set the tag's attribute, called inline style;

2. Use the

3. Create and Linking external CSS files, called external style sheets.

Basic style sheets usually modify the appearance of HTML tags such as

and

. When using CSS files or stylesheets in header files, we can also define style classes and apply them to any element using the class="?" attribute, but this is beyond the scope of this simple guide.

Inline style

Features:

1) Inline style is placed in the HTML element in the code.

2) When using inline styles, the styles will only affect the elements you select.

3), inline styles have no selectors

Note: Inline styles defined in HTML only apply to the tags they are added to.

<p style="color:red;">Some red text</p>

Advantages:

1. Very useful if you want to test and preview changes.

2. Very useful for quick repair.

3. Reduce HTTP requests.

Disadvantages:

Inline CSS must be applied to every element.

Embedded style

Features:

1), placed in the style tag

2), the style written will be used only for the web page you use it on.

3), embedded styles are also called "internal styles"

The styles defined in the header will be applied to the entire page. The example below will make all h1 tags in the page display the title in red.

<head>
   <style type="text/css"> 
       h1 { color: red; }
   </style>
</head>

Advantages:

1. The style sheet only affects one page.

2. Internal style sheets can use classes and IDs.

3. No need to upload multiple files. HTML and CSS can be in the same file.

Disadvantages:

1. Increase page loading time.

2. It only affects one page - useless if you want to use the same CSS on multiple documents.

External Style Sheets

Like HTML files, CSS files are plain text and usually have a .css file extension; they can be linked via specific tags into the HTML file.

Features:

1), written in a separate document and then attached to various Web documents

2), modifying it can affect all pages you call

3), easy to modify

For example, the content of the style.css file can be as follows:

body { background-color: beige; color: #000080;}
h1 { color: red;}

Then you can use The header is introduced to take effect.

<head>
<link rel="stylesheet" type="text/css" href="style.css" title="style">
</head>

Advantages:

1. The size of the HTML page is smaller and the structure is clearer.

2. Faster loading speed.

3. The same .css file can be used on multiple pages.

Disadvantages:

The page may not render correctly until external CSS is loaded.

The above is the detailed content of How to embed css into html?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)Orbital Mechanics (or How I Optimized a CSS Keyframes Animation)May 09, 2025 am 09:57 AM

What does it look like to refactor your own code? John Rhea picks apart an old CSS animation he wrote and walks through the thought process of optimizing it.

CSS Animations: Is it hard to create them?CSS Animations: Is it hard to create them?May 09, 2025 am 12:03 AM

CSSanimationsarenotinherentlyhardbutrequirepracticeandunderstandingofCSSpropertiesandtimingfunctions.1)Startwithsimpleanimationslikescalingabuttononhoverusingkeyframes.2)Useeasingfunctionslikecubic-bezierfornaturaleffects,suchasabounceanimation.3)For

@keyframes CSS: The most used tricks@keyframes CSS: The most used tricksMay 08, 2025 am 12:13 AM

@keyframesispopularduetoitsversatilityandpowerincreatingsmoothCSSanimations.Keytricksinclude:1)Definingsmoothtransitionsbetweenstates,2)Animatingmultiplepropertiessimultaneously,3)Usingvendorprefixesforbrowsercompatibility,4)CombiningwithJavaScriptfo

CSS Counters: A Comprehensive Guide to Automatic NumberingCSS Counters: A Comprehensive Guide to Automatic NumberingMay 07, 2025 pm 03:45 PM

CSSCountersareusedtomanageautomaticnumberinginwebdesigns.1)Theycanbeusedfortablesofcontents,listitems,andcustomnumbering.2)Advancedusesincludenestednumberingsystems.3)Challengesincludebrowsercompatibilityandperformanceissues.4)Creativeusesinvolvecust

Modern Scroll Shadows Using Scroll-Driven AnimationsModern Scroll Shadows Using Scroll-Driven AnimationsMay 07, 2025 am 10:34 AM

Using scroll shadows, especially for mobile devices, is a subtle bit of UX that Chris has covered before. Geoff covered a newer approach that uses the animation-timeline property. Here’s yet another way.

Revisiting Image MapsRevisiting Image MapsMay 07, 2025 am 09:40 AM

Let’s run through a quick refresher. Image maps date all the way back to HTML 3.2, where, first, server-side maps and then client-side maps defined clickable regions over an image using map and area elements.

State of Devs: A Survey for Every DeveloperState of Devs: A Survey for Every DeveloperMay 07, 2025 am 09:30 AM

The State of Devs survey is now open to participation, and unlike previous surveys it covers everything except code: career, workplace, but also health, hobbies, and more. 

What is CSS Grid?What is CSS Grid?Apr 30, 2025 pm 03:21 PM

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools