Home »
JavaScript Examples
How to create a bold text using JavaScript?
By IncludeHelp Last updated : November 08, 2023
How to create a bold text using JavaScript?
To create a bold text using JavaScript, we use HTML's <b> tag. This tag will display the bold text. You can also use JavaScript's bold() method but it is deprecated and is not supported by all brewers. So, the best way to create a bold text, use <b> tag.
Example
In this example, we are creating a bold text using JavaScript and displaying it in a paragraph (HTML's <p> tag).
<!DOCTYPE html>
<html>
<body>
<h1>Example: How to create a bold text using JavaScript?</h1>
<p>This is normal text</p>
<p>The bold text is below:</p>
<p id="displayText"></p>
<script type="text/javascript">
// define a string
let inputText = "Hello, world! How're you?";
// placing <b> tag
let result = "<b>" + inputText + "</b>"
// displaying text
document.getElementById("displayText").innerHTML = result;
</script>
</body>
</html>
Output
The output of the above code is:
JavaScript Examples »