JavaScript – Change Text in HTML Element to Bold

To change text in HTML Element to bold using JavaScript, get reference to this HTML Element, and assign property with value of "bold".

In the following example, we will make the text bold in HTML Element with id "myElement", in JavaScript, using property.


<!DOCTYPE html>
<html lang="en">
        #myElement {
            border:1px solid #CCC;
    <meta charset="utf-8">
    <h2>Make Text in HTML Element Bold using JavaScript</h2>
    <div id="myElement">Hello World!</div>
    <button type="button" onclick="changeStyle()">Click Me</button>
    function changeStyle(){
        var element = document.getElementById("myElement"); = "bold";
Try Online


In this JavaScript Tutorial, we learned how to change text in a HTML Element to bold using JavaScript.