HTML - DOM Document title Property



HTML DOM document title property is used to set or get the title of the document. The title property holds the information about the title.

Syntax

Set the Title Name
document.title = newTitle;
Get the Title Name
document.title;

Property

Value Description
newTitle It represents new title for the document.

Return Value

It returns a string value which represents the title of the document.

Examples of HTML DOM Document 'title' Property

The following examples illustrates how to set and return the title of the document.

Return the Title

The following example return the title name of the current document.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM document title Property
    </title>
</head>
<body>
    <button onclick="fun()">Click me</button>
    <p>The title of the document :</p>
    <p id="title"></p>
    <script>
        function fun() {
            let x = document.title;
            document.getElementById("title").innerHTML = x;
        }
    </script>
</body>
</html>

Set a New Title

The following example sets a new title name of the current document.

<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        HTML DOM document title Property
    </title>
</head>
<body>
    <button onclick="fun()">Click me</button>
    <p>The new title of the document is:</p>
    <p id="title"></p>
    <script>
        function fun() {
            let x = document.title = "Title Property";
            document.getElementById("title").innerHTML = x;
        }
    </script>
</body>
</html>

Supported Browsers

Property Chrome Edge Firefox Safari Opera
title Yes 1 Yes 12 Yes 1 Yes 1 Yes 12.1
html_dom.htm
Advertisements