Course Content
HTML Basic Examples
In this chapter we will show some basic HTML examples. Don't worry if we use tags you have not learned about yet.
0/1
HTML Editors
A simple text editor is all you need to learn HTML.
0/1
HTML Basic Examples
In this chapter we will show some basic HTML examples.
0/1
HTML Elements
0/1
HTML Attributes
HTML attributes provide additional information about HTML elements.
0/1
HTML Headings
HTML headings are titles or subtitles that you want to display on a webpage.
0/1
HTML Paragraphs
A paragraph always starts on a new line, and is usually a block of text.
0/1
HTML Styles
The HTML style attribute is used to add styles to an element, such as color, font, size, and more.
0/1
HTML Text Formatting
HTML contains several elements for defining text with a special meaning
0/1
HTML Quotation and Citation Elements
0/1
HTML Comments
0/1
HTML Styles – CSS
0/1
HTML Favicon
0/1
HTML Page Title
0/1
HTML Block and Inline Elements
0/1
HTML Div Element
0/1
HTML class Attribute
0/1
HTML id Attribute
0/1
HTML Iframes
0/1
HTML JavaScript
0/1
HTML File Paths
0/1
HTML – The Head Element
0/1
HTML Layout Elements and Techniques
HTML Tutorial
About Lesson
How To Use HTML Attributes

HTML attributes can be used to change the color, size, and other features of HTML elements. For example, you can use an attribute

to change the color or size of a font for a text element or the width and height for an image element. In this tutorial,

we’ll learn how to use HTML attributes to set values for the size and color properties of HTML text elements.

An HTML attribute is placed in the opening tag like this:

      <element attribute="property:value;">
 

One common attribute is style, which allows you to add style properties to an HTML element.

While it’s more common to use a separate stylesheet to determine the style of an HTML document,

we will use the style attribute in our HTML document for this tutorial.

Using the Style Attribute

We can change multiple properties of an <h1> element with the style attribute.

Clear your “index.html” file and paste the code below into your browser.

(If you have not been following the tutorial series, you can review instructions for setting up an index.html file in our tutorial Setting Up Your HTML Project.

<h1 style=font-size:40px;color:black;>This text is 40 pixels and green.</h1>

 

Before we load the file in our browser, let’s review each of the parts of this HTML element:

  • h1 is the name of the tag. It refers to the largest-sized Heading element.
  • style is the attribute. This attribute can take a variety of different properties.
  • font-size is the first property we’re setting for the style attribute.
  • 40px; is the value for the property font-size, which sets the text content of the element to 40 pixels.
  • color is the second property we’re setting for the style attribute.
  • black is the value for the property color, which sets the text content color to green

Note that the properties and values are contained by quotation marks, and that each property:value pair ends with a semicolon ;.

Save the file and reload it in your browser. (For instructions on loading the file in your browser, see our tutorial here.) You should receive something like this:

 

This text is 40 pixels and black.

You have now learned how to use the style attribute to change the font size and font color of a text element.

Note that certain elements require attributes, such as the <a> element which allows you to add a link to a text or image,

and the <img> element, which allows you to add an image to the document.

We’ll cover those two elements in the next tutorials and learn about additional attribute usage for <div> containers and other HTML elements later on in the tutorial series.