share

Display Custom Code Snippets on Your Website

April 22, 2018 | Code Snippets, Dev / Code

If you’re a developer, designer, programmer, or any other title that may require displaying your code on the frontend of your website, this article may be for you.

We’ve all had to do a Google search to find out how to do some sort of CSS, javascript, php, etc. Chances are, you’ve seen the a code snippet displayed on the frontend of a website.

Most frameworks (like Bootstrap) have pre-built styles they attribute to <code></code> tags, but they are all very boring.

How do I display code on my website?

Simply put, using the <code> </code> element shows code without it being attributed to the pages elements.

Here is an example of Bootstrap’s default styling for the <code></code> attribute.

code {
padding: 2px 4px;
font-size: 90%;
color: #c7254e;
background-color: #f9f2f4;
border-radius: 4px;
width: 100%;
}

That shit is boring.

Changing the background only effects the text displayed, but there is a simple solution.

The most common method is to wrap the <code></code> attribute in a <pre></pre> (preforamatted text element) .

Doing this allows you to style the background of the entire element rather than just the text.

Here is an example:


pre {
    background: #1C1E2C;
    border: 0px;
    width: 100%;
    padding: 40px;
    color: #fff;
    width: 100%;
    font-size: 18px;
    line-height: 29px
}

The CSS styling displayed within that snippet is the taken directly from our CSS.

Share this Post

Submit a Topic

Get a Product Review

Advertise With Us

Who wrote dis?

matt McKenna

Founder of DELT; a branding agency in St. Louis

  • Haven’t signed up for our newsletter?

    Be a lot cooler if ya did


    We send nothing but the good shit. Once a week. That’s it.

    Be a lot cooler if ya did

    UX and Web Design blog articles
    Web Development & Coding blog articles
    Lifestyle blog articles
    Branding blog articles
    Graphic design blog articles
    Software reviews blog articles

    Time's up, let's do this

    Stay up-to-date with all of the design and creative news, resources, and inspiration by signing up for the CreativesFeed newsletter!