/

HTML / CSS / JavaScript Tutorial

HTML Element: <h2>

[this page | pdf | back links]

The HTML <h2> element indicates a level 2 HTML heading.

 

The attributes it can take are HTML global attributes and HTML event attributes.

 

It used to support the align attribute, but this is no longer supported in HTML 5.

 

To create or access such an element in JavaScript see here. The corresponding HTML DOM object supports standard DOM properties and methods. The default style applicable to this element is shown here.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
Created using HTML:<br>
<h2>Heading 2</h2>

<br><br>Created using JavaScript:<br>
<span id="element"></span>

<script>
var y = document.getElementById("element");
var x2 = document.createElement("H2");
x2.textContent = "Heading 2";
y.appendChild(x2);
</script>

</body>
</html>


NAVIGATION LINKS
Contents | Prev | Next | HTML Elements


Desktop view | Switch to Mobile