How do I wrap text in <code> tag HTML
This article is on how to wrap text in code tag in html. We will use white-pace, word-break and word-wrap CSS property to get our result.
In this article we will see how to wrap text in code tag in our html.
< code > tag in HTML is used to represent computer code. This is very helpful when you are writing a post for a programming blog.
The code tag have a fixed-width and browsers display it's content in monospace font.
Recently while working on a article, i came across a issue using code tag in mobile version of my website. Since it have a fixed-width, it exceeds the max-width of my mobile-device , and so i get a horizontal-scroll in my website.
So to fixed i have to use some CSS property to fixed the issue, if you facing the same issue just use the code below.
code{ display: inline-block; white-space: normal; max-width:100%; word-break:break-all; word-wrap:break-word; }
white-space : It handles the white space inside the code tag.
word-break : It handle how the word should break once it reach the end of the line.
word-wrap : It help to break long word and move to the next line.
Related Posts
How to change the color of <hr> tag using CSS
Here we will learn how to change the color or the background color of HR element in out html using css style.
Horizontal scrolling div with arrows using HTML and CSS
Tutorial on how to make horizontal scrolling div with arrows using html and css and for smooth scrolling we will use scrollBy() function in Javascript.
What is insertAdjacentHTML() ? How to use it?
Tutorial on Javascript insertAdjacentHTML() method and how can we use it to insert html elements to specific position in our HTML page.
How to make a placeholder for select box in HTML
Short tutorial on how we can add placeholder text for the select option element for dropdown in Html without CSS.
