HTML Styles – CSS
CSS stands for Cascading Style Sheets.
CSS saves a lot of work. It can control the layout of multiple web pages all at once.
CSS = Styles and Colors
What is CSS?
Cascading Style Sheets (CSS) is used to format the layout of a webpage.
With CSS, you can control the color, font, the size of text, the spacing between elements, how elements are positioned and laid out, what background images or background colors are to be used, different displays for different devices and screen sizes, and much more!
Tip: The word cascading means that a style applied to a parent element will also apply to all children elements within the parent. So, if you set the color of the body text to “blue”, all headings, paragraphs, and other text elements within the body will also get the same color (unless you specify something else)!
Using CSS
CSS can be added to HTML documents in 3 ways:
- Inline – by using the
style
attribute inside HTML elements - Internal – by using a
<style>
element in the<head>
section - External – by using a
<link>
element to link to an external CSS file
The most common way to add CSS, is to keep the styles in external CSS files. However, in this tutorial we will use inline and internal styles, because this is easier to demonstrate, and easier for you to try it yourself.
Inline CSS
An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style
attribute of an HTML element.
The following example sets the text color of the <h1>
element to blue, and the text color of the <p>
element to red:
Example
<h1 style="color:blue;">A Blue Heading</h1> <p style="color:red;">A red paragraph.</p>
Internal CSS
An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the <head>
section of an HTML page, within a <style>
element.
The following example sets the text color of ALL the <h1>
elements (on that page) to blue, and the text color of ALL the <p>
elements to red. In addition, the page will be displayed with a “powderblue” background color:
Example
<!DOCTYPE html> <html> <head> <style> body {background-color: powderblue;} h1 {color: blue;} p {color: red;} </style> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body> </html>
External CSS
An external style sheet is used to define the style for many HTML pages.
To use an external style sheet, add a link to it in the <head>
section of each HTML page:
Example
<!DOCTYPE html> <html> <head> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body> </html>
The external style sheet can be written in any text editor. The file must not contain any HTML code, and must be saved with a .css extension.
Here is what the “styles.css” file looks like:
“styles.css”:
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p {
color: red;
}
Tip: With an external style sheet, you can change the look of an entire web site, by changing one file!
CSS Colors, Fonts and Sizes
Here, we will demonstrate some commonly used CSS properties. You will learn more about them later.
The CSS color
property defines the text color to be used.
The CSS font-family
property defines the font to be used.
The CSS font-size
property defines the text size to be used.
Example
Use of CSS color, font-family and font-size properties:
<!DOCTYPE html> <html> <head> <style> h1 { color: blue; font-family: verdana; font-size: 300%; } p { color: red; font-family: courier; font-size: 160%; } </style> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> </body> </html>
CSS Border
The CSS border
property defines a border around an HTML element.
Tip: You can define a border for nearly all HTML elements.
Example
Use of CSS border property:
p {
border: 2px solid powderblue;
}
CSS Padding
The CSS padding
property defines a padding (space) between the text and the border.
Example
Use of CSS border and padding properties:
p {
border: 2px solid powderblue;
padding: 30px;
}
CSS Margin
The CSS margin
property defines a margin (space) outside the border.
Example
Use of CSS border and margin properties:
p {
border: 2px solid powderblue;
margin: 50px;
}
Link to External CSS
External style sheets can be referenced with a full URL or with a path relative to the current web page.
Example
This example uses a full URL to link to a style sheet:
<link rel=”stylesheet” href=”https://www.w3schools.com/html/styles.css”>
Example
This example links to a style sheet located in the html folder on the current web site:
<link rel="stylesheet" href="/html/styles.css">
Example
This example links to a style sheet located in the same folder as the current page:
<link rel="stylesheet" href="styles.css">
Chapter Summary
- Use the HTML
style
attribute for inline styling - Use the HTML
<style>
element to define internal CSS - Use the HTML
<link>
element to refer to an external CSS file - Use the HTML
<head>
element to store <style> and <link> elements - Use the CSS
color
property for text colors - Use the CSS
font-family
property for text fonts - Use the CSS
font-size
property for text sizes - Use the CSS
border
property for borders - Use the CSS
padding
property for space inside the border - Use the CSS
margin
property for space outside the border
49 Responses
brand cialis online Forum Viagra 50mg
Amoxicillin Effects On Liver buy stromectol 6 mg online
Фильмы музыка сериалы онлайн
de Jong van den Berg stromectol dosage for head lice
Гў Gaston PXlRghFBXwtJHRCFs 6 19 2022 tamoxifen buy online B In MCF 7 cells were treated with the indicated combinations of 200 ОјM I3C and 5 mM MG132
Preclinical and clinical data for tamoxifen in muscular dystrophy are promising and the findings suggest its usage also in patients with DMD buy clomid australian dollars
However, most studies that have investigated the association between CLA intake in the diet and risk of breast cancer in women have failed to find a protective effect for CLA doxycycline genital infection
levaquin 250mg drug cost levofloxacin
dutasteride cheap order generic flomax 0.4mg ondansetron 4mg uk
cost spironolactone 100mg order diflucan for sale fluconazole oral
acillin over the counter purchase erythromycin without prescription buy erythromycin sale
buy sildenafil 100mg online cheap order fildena 100mg online robaxin 500mg without prescription
2004; Menn et al levitra comprime 136 Men with increased FSH levels may require additional assisted reproductive treatment to achieve a pregnancy even after successful surgery
suhagra 50mg for sale estrace 2mg oral estradiol order
lamictal pills buy lamotrigine sale retin gel cost
buy tadalis 20mg generic order tadacip generic voltaren 100mg price
isotretinoin 20mg over the counter buy generic amoxil 1000mg buy zithromax 250mg pill
oral indomethacin buy trimox 250mg for sale trimox online order
J Natl Cancer Inst 103, 1461 1468 2011 clomid calculator From a purely payment Read Full Post
buy tadalafil 40mg sale supplements for ed buy viagra 50mg sale
anastrozole 1 mg for sale order arimidex 1 mg order viagra without prescription
TAZ deficiency does not alter autophagy under basal and starvation conditions buy cialis non prescription
It stops it from hurting viagra alternatives over the counter com 20 E2 AD 90 20Viagra 20Hap 20 20Viagra 20Fiyatlar 2050 20Mg viagra fiyatlar 50 mg The expectation is for a better than expected reportingseason, particularly from the domestic industrials sector, whichhas been very weak for the past five halves, said Martin Lakos, division director at Macquarie Bank
tadalafil 20mg gГ©nГ©rique viagra 100mg generique pas cher viagra 25mg en ligne
prednisone price viagra 100mg pill sildenafil 100mg tablet
tadalafil 20mg ohne rezept viagra 200mg kaufen ohne rezept viagra 100mg ohne rezept
isotretinoin 10mg uk generic azithromycin ivermectin 3mg dose
order doxycycline 100mg online order clomiphene 50mg generic purchase lasix generic
order altace 10mg online cheap order astelin online cheap oral astelin 10ml
order clonidine 0.1mg sale antivert 25 mg for sale spiriva price
buspirone 5mg cheap buspirone sale oral ditropan 5mg
hytrin 5mg usa order azulfidine azulfidine 500 mg pills
fosamax 70mg over the counter alendronate 35mg without prescription order famotidine 20mg generic
imdur 20mg cheap imdur drug order micardis pill
bupropion over the counter buy zyrtec online quetiapine 100mg canada
order molnunat online cheap cheap omnicef 300 mg lansoprazole medication
buy salbutamol 100 mcg online protonix 20mg us order viagra 100mg generic
purchase tadalafil for sale natural viagra alternatives purchase viagra generic
cheap cialis 20mg cialis 5mg cheap amantadine 100mg generic
order naltrexone generic buy letrozole 2.5mg pill abilify 20mg sale
buy avlosulfon online order generic adalat 30mg brand perindopril 8mg
provera drug order generic microzide brand cyproheptadine
buy modafinil 200mg generic buy modafinil online ivermectin 3 mg tablet dosage
fluvoxamine price cymbalta order generic glucotrol 5mg
order piracetam sildenafil 50mg cheap sildenafil 50mg cost
buy azithromycin sale zithromax 250mg generic order gabapentin online cheap
tadalafil 10mg drug purchase viagra sildenafil on line
lasix pill cheap hydroxychloroquine order hydroxychloroquine 200mg for sale
tadalafil liquid betamethasone tablet generic clomipramine 50mg