In this topic we will learn how to use html with CSS. CSS(Cascading Style Sheets) is used to apply style on the web page which is made up of HTML elements.
CSS describes the look of the webpage and it provides different style properties such as text-color, background-color, padding, margin, and many more to style webpage.
CSS saves time, you can write CSS once and then reuse that sheet in multiple HTML pages.
Three ways to apply CSS:
Inline CSS: Define CSS using style attribute in the HTML elements
Internal CSS: Define CSS using <style> tag in <head> section
External CSS: Define CSS in a separate .css file
It is the best way to keep the styles in separate CSS files. You can define a style for each HTML element and apply it to multiple Web pages as you want.
Inline CSS:
The inline CSS helps you apply CSS to specific HTML elements. The style attribute is used in the HTML element to apply inline CSS. You can apply multiple properties as you want, you just have to separate each property by a semicolon(;).
Example:
<h2 style="color: #ff5722; font-style:italic; text-align:center;"> This is HTML with Inline CSS </h2>
The internal CSS is used to add a unique style for a single document.
The internal CSS is defined in <head> section of the HTML page inside the <style> tag.
The class and id attributes are used with internal CSS.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-color: #ff5722;
}
h2 {
color: #fff;
text-align: center;
padding: 10px;
}
p {
color: #fff;
text-align: center;
padding: 10px;
font-size: 20px;
}
</style>
</head>
<body>
<div>
<h2> HTML </h2>
<p> HTML is a markup language using which you can create your website. HTML stands for Hypertext Markup Language. It contains elements and the elements are represented by tags. </p>
An external style sheet is a separate CSS file that only contains style code using the class name. id name etc.
Using an external style sheet you can change the look of the entire web page by changing one file.
You can use this CSS file in any HTML file by including it in the <head> section of the HTML page.
If you have multiple HTML pages for an application which have similar CSS, then you can use external CSS.
Example:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h2> HTML </h2>
<p> HTML is a markup language using which you can create your website. HTML stands for Hypertext Markup Language. It contains elements and the elements are represented by tags. </p>
You can write external CSS in any editor and save that CSS file with .css extension.
Example:
div {
background-color: #ff5722;
}
h2 {
color: #fff;
text-align: center;
padding: 10px;
}
p {
color: #fff;
text-align: center;
padding: 10px;
font-size: 20px;
}
CSS Fonts:
The CSS color property is used to set the color of the text.
The CSS font-family property is used to change the font of the text.
The CSS font-size property is used to increase or decrease the size of the text.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
h2 {
color: #ff5722;
font-family: algerian;
font-size: 40px;
}
p {
color: #ff5722;
font-family: calibri;
font-size: 25px;
}
</style>
</head>
<body>
<div>
<h2> HTML </h2>
<p> HTML is a markup language using which you can create your website. HTML stands for Hypertext Markup Language. It contains elements and the elements are represented by tags. </p>
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok