Curriculum
Course: HTML Basic
Login

Curriculum

HTML Basic

HTML Introduction

0/1

HTML Editors

0/1

HTML Elements

0/1

HTML Attributes

0/1

HTML Headings

0/1

HTML Paragraphs

0/1

HTML Styles

0/1

HTML Formatting

0/1

HTML Quotation

0/1

HTML Comments

0/1

HTML Colors

0/1

HTML Favicon

0/1

HTML Page Title

0/1

HTML Block and Inline

0/1

HTML Iframes

0/1

HTML Java Script

0/1

HTML File Paths

0/1

HTML - The Head Element

0/1

HTML Style Guide

0/1

HTML Entities

0/1

HTML Symbols

0/1
Text lesson

HTML CSS

CSS allows for the styling and layout of web pages, enabling control over aspects such as text color and size, font styles, spacing between elements, positioning, and layout. It also facilitates the use of background images or colors, and enables tailored displays for various devices and screen sizes, among other features.

Tip: The term “cascading” indicates that a style assigned to a parent element will also be inherited by all child elements within it. Therefore, if you designate the color of the body text as “blue,” all headings, paragraphs, and other text elements within the body will similarly adopt that color (unless otherwise specified)!

Using CSS

There are three methods to incorporate CSS into HTML documents:

  • Inline: This involves utilizing the style attribute directly within HTML tags.
  • Internal: This method entails placing CSS rules within a <style> tag located in the <head> section of the HTML document.
  • External: CSS is applied by linking to an external stylesheet file through a<link> element.

While the most common practice is to maintain styles in separate, external CSS files, this tutorial will focus on inline and internal styles for simplicity and to facilitate hands-on learning.

Inline CSS

Inline CSS is employed to assign a specific style to an individual HTML element.

This approach utilizes the style attribute within an HTML tag.

In the example below, the color of the text within the <h1> tag is changed to blue, while the text within the <p> tag is altered to red:

Example

<h1 style=”color:blue;”>A Blue Heading</h1>

<p style=”color:red;”>A red paragraph.</p>

 

Click to Learn

 

Internal CSS

Internal CSS is utilized to establish styling rules for a specific HTML document.

Such CSS rules are placed within a style element located in the <head> section of the HTML document.

In the provided example, the styling directives set the text color of every <h1> element on the page to blue and every <p> element to red. Moreover, the background color of the entire page is set to “powderblue”.

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>

 

Click to Learn

 

External CSS

An external stylesheet is employed to apply consistent styling across multiple HTML documents.

To integrate an external stylesheet, a link to it is inserted within the <head> section of each HTML document.

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>

You can create an external stylesheet using any text editor. Ensure the file is purely composed of CSS code, without any HTML elements, and is saved with the “.css” file extension

Below is an example of what the content in a “styles.css” file might resemble:

“styles.css”:

body {
  background-color: powderblue;
}
h1 {
  color: blue;
}
{
  color: red;
}

 

Click to Learn

 

Tip: Using an external style sheet allows you to alter the appearance of an entire website by modifying just one file!

CSS Colors, Fonts and Sizes

In this section, we’ll introduce a few widely utilized CSS properties, which we’ll explore in greater detail later on.

The color property in CSS specifies the color of the text.

The font-family‘ property in CSS determines the font style to be applied.

The font-size property in CSS sets the size of the text.

Example

<!DOCTYPE html>
<html>
<head>
<style>
h1 {
  color: blue;
  font-family: verdana;
  font-size: 300%;
}
{
  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>

 

Click to Learn

 

CSS Border

The ‘border‘ property in CSS is used to create a border surrounding an HTML element.

Note: Almost every HTML element can have a border defined for it.

Example

{
  border: 2px solid powderblue;
}

 

Click to Learn

 

CSS Padding

The padding property in CSS is utilized to create space between the text and its surrounding border.

Example

Utilizing CSS border and padding properties:

{
  border: 2px solid powderblue;
  padding: 30px;
}

 

Click to Learn

 

CSS Margin

The margin property in CSS specifies the space outside an element’s border.

Example

Utilizing CSS border and margin properties:

{
  border: 2px solid powderblue;
  margin: 50px;
}

 

Click to Learn

 

Link to External CSS

External stylesheets can be linked using either a complete URL or a path that is relative to the current webpage.

Example

Using CSS border and margin properties:

<link rel=”stylesheet” href=”https://www.w3schools.com/html/styles.css”>

Example

<link rel=”stylesheet” href=”/html/styles.css”>

Example

<link rel=”stylesheet” href=”styles.css”>

 

Click to Learn

 

Chapter Summary

  • For inline styling, utilize the ‘style‘ attribute within HTML tags.
  • For defining internal CSS, employ a ‘<style>‘ tag inside the HTML document.
  • To link to an external CSS file, use a ‘<link>‘ element.
  • Store ‘<style>‘ and ‘<link>‘ elements within the ‘<head>‘ section of the HTML document.
  • To change text colors, apply the ‘color‘ property in CSS.
  • To set the font type for text, use the ‘font-family‘ property in CSS.
  • To adjust text sizes, use the ‘font-size‘ property in CSS.
  • For creating borders, utilize the ‘border‘ property in CSS.
  • For adding space inside borders, employ the ‘padding‘ property in CSS.
  • For adding space outside borders, use the ‘margin‘ property in CSS.

 

HTML Style Tags

The <style> tag is used to specify styling details for an HTML document, while the <link> tag is used to establish a connection between the document and an external resource.