The <div align=""> attribute is used for aligning the text in a div tag to The Left, Right, center or justify.
Learn to code β free 3,000-hour curriculum
NOVEMBER 24, 2019
/
#HTML
The Best HTML Examples and HTML5 Examples
The Best HTML Examples and HTML5 Examples
HTML provides the structure of websites. Here are some examples of how to use HTML syntax to build websites, including some examples of newer HTML5 features.
The A Href Attribute Example
The <a href> attribute refers to a destination provided by a link. The a (anchor) tag is dead without the <href> attribute. Sometimes in your workflow, you donβt want a live link or you wonβt know the link destination yet. In this case, itβs useful to set the href attribute to "#" to create a dead link. The hrefattribute can be used to link to local files or files on the internet.
For instance:
<html>
<head>
<title>Href Attribute Example</title>
</head>
<body>
<h1>Href Attribute Example</h1>
<p>
<a href="https://www.freecodecamp.org/contribute/">The freeCodeCamp Contribution Page</a> shows you how and where you can contribute to freeCodeCamp's community and growth.
</p>
</body>
</html>
The <a href> attribute is supported by all browsers.
More attributes:
hreflang : Specifies the language of the linked resource. target : Specifies the context in which the linked resource will open. title : Defines the title of a link, which appears to the user as a tooltip.
Examples
<a href="#">This is a dead link</a>
<a href="https://www.freecodecamp.org">This is a live link to freeCodeCamp</a>
<a href="https://html.com/attributes/a-href/">more with a href attribute</a>
In-page anchors
Itβs also possible to set an anchor to certain place of the page. To do this you should first place a tab at location on the page with tag and necessary attribute βnameβ with any keyword description in it, like this:
<a name="top"></a>
Any description between tags is not required. After that you can place a link leading to this anchor at any palce on same page. To do this you should use tag with necessary attribute βhrefβ with symbol # (sharp) and key-word description of the anchor, like this:
<a href="#top">Go to Top</a>
Image Links
The <a href="#"> may also be applied to images and other HTML elements.
Example
<a href="#">
<img itemprop="image" style="height: 90px;" src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back.">
</a>
Example
The A Target Example
The <a target> attribute specifies where to open the linked document in an a (anchor) tag.
Examples:
A target attribute with the value of β_blankβ opens the linked document in a new window or tab.
<a href="https://www.freecodecamp.org/" target="_blank">freeCodeCamp</a>
A target attribute with the value of β_selfβ opens the linked document in the same frame as it was clicked (this is the default and usually does not need to be specified).
<a href="https://www.freecodecamp.org/" target="_self">freeCodeCamp</a>
<a href="https://www.freecodecamp.org/">freeCodeCamp</a>
A target attribute with the value of β_parentβ opens the linked document in the parent frame.
<a href="https://www.freecodecamp.org/" target="_parent">freeCodeCamp</a>
A target attribute with the value of β_topβ opens the linked document in the full body of the window.
<a href="https://www.freecodecamp.org/" target="_top">freeCodeCamp</a>
A target attribute with the value of βframenameβ Opens the linked document in a specified named frame.
<a href="https://www.freecodecamp.org/" target="framename">freeCodeCamp</a>
The Body Background Attribute Example
If you want to add a background image instead of a color, one solution is the <body background> attribute. It specifies a background image for an HTML document.
Syntax:
<body background="URL">
Attribute:
background - URL for background image
Example:
<html>
<body background="https://assets.digitalocean.com/blog/static/hacktoberfest-is-back/hero.png">
</body>
</html>
body-background attribute is depreciated
the body-background attribute been deprecated in HTML5. The correct way to style the <body> tag is with CSS.
There are several CSS properties used for setting the background of an element. These can be used on to set the background of an entire page.
The Body Bgcolor Attribute Example
The <body bgcolor> attribute assigns a background color for an HTML document.
Syntax:
<body bgcolor="color"> The color value can be either a color name (like, purple) or a hex value (like, #af0000).
To add a background color to a webpage you can use the <body bgcolor="######"> attribute. It specifies a color for the HTML document to display.
For example:
<html>
<head>
<title>Body bgcolor Attribute example</title>
</head>
<body bgcolor="#afafaf">
<h1>This webpage has colored background.</h1>
</body>
</html>
You can change the color by replacing ###### with a hexadecimal value. For simple colors you can also use the word, such as βredβ or βblackβ.
All major browsers support the <body bgcolor> attribute.
Note:
HTML 5 does not support the <body bgcolor> attribute. Use CSS for this purpose. How? By using the following code: <body style="background-color: color"> Of course, you can also do it in a separate document instead of an inline method.
Do not use RGB value in <body bgcolor> attribute because rgb() is for CSS only, that is, it will not work in HTML.
The Div Align Attribute Example
The <div align=""> attribute is used for aligning the text in a div tag to The Left, Right, center or justify.
For instance:
<html>
<head>
<title>Div Align Attribbute</title>
</head>
<body>
<div align="left">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
</div>
<div align="right">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
</div>
<div align="center">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
</div>
<div align="justify">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua.
</div>
</body>
</html>