How do I wrap text in code tag HTML

featured Image

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

git commands with example

Top 40 Git commands with Examples

GitHub has become an essential tool for developers to manage, store, and collaborate with other developers on software projects. With its simple powerful git-based version control system, GitHub allows users…

Read more
Check GitHub Account in the Terminal

Check GitHub Account in the Terminal

GitHub is an integral tool for developers to store, manage, and collaborate on software projects with other developers. And as we work more and more in the command line it…

Read more
featured Image

How to make list of objects in Netlify CMS using list and object Widget

Here in this Netlify CMS tutorial we will how easily we can make a list of objects using list and object widgets. This will allow us to add multiple objects…

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *