Click here to Skip to main content
15,881,781 members
Articles / Web Development / HTML
Tip/Trick

Article Formatting tips for CodeProject

Rate me:
Please Sign up or sign in to vote.
5.00/5 (33 votes)
26 Feb 2015CPOL5 min read 81.4K   33   20
Some tips and tricks to help you format your articles and tips simply and consistently.

Introduction

When posting an article on CodeProject we want you to focus on your article's content, not on fancy HTML and CSS tricks. The simpler and cleaner the layout, the easier it is for your readers to consume your work.

With this in mind we've put together some simple rules, guidelines and tricks to help make your life a little easier.

The Motivation

We want the experience of reading an article on CodeProject to be a consistent one. From article to article the layout, styles and formatting should be reasonably uniform in order to make it easy to read.

We also need the freedom to update our stylesheets occasionally, and so sticking to a few simple rules and guidelines allows your articles to maintain current styling without breaking or looking...odd.

The Rules

  1. Stick to HTML conventions and use HTML tags as they were meant to be used.

    If you use BLOCKQUOTE to indent text then you're assuming the BLOCKQUOTE tag actually indents text on all browsers, and you're also assuming we haven't used CSS to add quote marks or other shenanigans to the output. Use a styled DIV if you wish to indent,

    Similarly, use P tags to denote paragraphs. Please don't use BR tags to break paragraphs.
     
  2. Use simple HTML only.

    By this we mean: stick to the simplest, cleanest HTML possible. Use B or STRONG to make text bold, use CODE tags to outline inline code, and PRE to wrap codeblocks. Don't wrap everything in SPAN blocks with crazy styles: our online editor (and our human editors) will most likely strip it all out.
     
  3. No active content such as Javascript or Flash

    You won't have permission to add this to your articles anyway. It's a security risk (and potentially annoying to readers). However: if you have a compelling reason you want to have live Javascript in your articles then contact us and we can make exceptions. 

The Guidelines

  1. Where possible stick to using our predefined classes when styling HTML elements instead of using inlined styles.
    • SPAN elements can use the filename, command, error, success, and failure classes. e.g.
      HTML
      <span class="command">Save File</span>
    • TABLE elements use the simple, themed, grid, feature and spaced classes. Take note of the use of THEAD elements.
      HTML
      <table class="simple" cellspacing="0" cellpadding="0">
      <thead>
      <tr><td>Col 1</td><td>Col 2</td><td>Col 3</td></tr>
      </thead>
      <tbody><tr><td>1</td><td>2</td><td>3</td></tr>
      <tr><td>A</td><td>B</td><td>C</td></tr>
      </tbody></table>

      Result:

      Col 1 Col 2 Col 3
      1 2 3
      A B C
      HTML
      <table class="themed" cellspacing="0" cellpadding="0">
      <thead>
      <tr><td>Col 1</td><td>Col 2</td><td>Col 3</td></tr>
      </thead>
      <tbody><tr><td>1</td><td>2</td><td>3</td></tr>
      <tr><td>A</td><td>B</td><td>C</td></tr>
      </tbody></table>

      Result:

      Col 1 Col 2 Col 3
      1 2 3
      A B C
      HTML
      <table class="feature" cellspacing="0" cellpadding="0">
      <thead>
      <tr><td>Col 1</td><td>Col 2</td><td>Col 3</td></tr>
      </thead>
      <tbody><tr><td>1</td><td>2</td><td>3</td></tr>
      <tr><td>A</td><td>B</td><td>C</td></tr>
      </tbody></table>

      Result:

      Col 1 Col 2 Col 3
      1 2 3
      A B C
      HTML
      <table class="grid" cellspacing="0" cellpadding="0">
      <thead>
      <tr><td>Col 1</td><td>Col 2</td><td>Col 3</td></tr>
      </thead>
      <tbody><tr><td>1</td><td>2</td><td>3</td></tr>
      <tr><td>A</td><td>B</td><td>C</td></tr>
      </tbody></table>

      Result:

      Col 1 Col 2 Col 3
      1 2 3
      A B

       
    •  DIV elements you can use the following:
      HTML
      <div class="callout">This is a callout</div>
      This is a callout
      HTML
      <div class="sidebar-left">This is a left-sidebar</div>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse commodo arcu eget scelerisque ultricies. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Ut erat nisl, faucibus eleifend ultricies sit amet, aliquam vitae velit. Nunc feugiat gravida convallis. Ut quis odio rhoncus, facilisis quam at, aliquet velit. Aliquam nec bibendum nulla, quis sollicitudin felis. Maecenas vitae auctor augue, consequat placerat odio. Mauris ac vulputate nisi. Morbi quis enim aliquam, iaculis eros non, vulputate nibh
       
      HTML
      <div class="sidebar-right">This is a right-sidebar</div>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse commodo arcu eget scelerisque ultricies. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Ut erat nisl, faucibus eleifend ultricies sit amet, aliquam vitae velit. Nunc feugiat gravida convallis. Ut quis odio rhoncus, facilisis quam at, aliquet velit. Aliquam nec bibendum nulla, quis sollicitudin felis. Maecenas vitae auctor augue, consequat placerat odio. Mauris ac vulputate nisi. Morbi quis enim aliquam, iaculis eros non, vulputate nibh
      HTML
      <div class="sidebar">This is a sidebar (no float or outer text wrapping)</div>
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse commodo arcu eget scelerisque ultricies. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Ut erat nisl, faucibus eleifend ultricies sit amet, aliquam vitae velit. Nunc feugiat gravida convallis. Ut quis odio rhoncus, facilisis quam at, aliquet velit. Aliquam nec bibendum nulla, quis sollicitudin felis. Maecenas vitae auctor augue, consequat placerat odio. Mauris ac vulputate nisi. Morbi quis enim aliquam, iaculis eros non, vulputate nibh
       
    • A elements can use the external class to indicate a link to an outside source:
      HTML
      <a class="external" href="http://www.google.com">Remember to search first, then ask.</a>

      Remember to search first, then ask

  2. Reduce or eliminate additional spacing or padding around elements

    Spacing around elements should be left to our stylesheets to manage. There are exceptions, though such as when you want to control spacing around floating elements. 

    To eliminate spacing use class="tight" on elements, and to provide standard spacing use class="spaced".
     
  3. Ensure elements are less than 700px wide.

    Otherwise elements in your article will either not fit on all screens or will have scrollbars added to them.
     
  4. Keep codeblocks as small as possible

    No one needs to wade through 1,000 lines of inlined code. Edit out the bits that aren't directly relevant to the explanation. The code will be available in your code download, so no need to repeat yourself.

The Tips and Tricks

  • Multiple language versions of the same code

    When including code samples within the article text you can provide the same code sample in multiple languages and have them displayed as a neat set of tabs, one tab per language. To do this, post your code samples one after the other, then wrap all the in a DIV with class "code-samples". e.g..
    ASP.NET
    <div class="code-samples">
    <pre lang="C#">
    ...
    // some C# code
    ...
    </pre>
    <pre lang="VB.NET">
    ...
    ' some VB code
    ...
    </pre>
    </div>

    This will result in

    C#
    ...
    // some C# code
    ...
    VB.NET
    ...
    ' some VB code
    ...

     
  • Adding line counts to code blocks

    When including code samples you can have line numbers automatically included be adding linecount="on" to the PRE tag. If you want to start the numbering at a specific line, use countstart="<start>", and to set the line count increment use countincrement="<increment>". eg
    ASP.NET
    <pre lang="aspnet" linecount="true">
    or
    ASP.NET
    <pre lang="vb" linecount="true" countstart="10" countincrement="10"> 

    This will result in

    VB
     10  PRINT "HELLO WORLD"
     20  GOTO 10	
    

     
  • Using LaTeX in your articles

    You can use MathML or TeX in your articles via MathJax. 

    Enclose your mathematics within a tag of class "math" and use $...$ to wrap equation blocks and  \(...\) to wrap inline equations.  eg <div class="math">$...$</div>, and wrap an inline equation with <span class="math">\(...\)</span>.

    For example:
    HTML
    <div class="math">
    $\begin{aligned}
    \dot{x} & = \sigma(y-x) \\
    \dot{y} & = \rho x - y - xz \\
    \dot{z} & = -\beta z + xy
    \end{aligned}$
    </div> 
    will render as
    $\begin{aligned} \dot{x} & = \sigma(y-x) \\ \dot{y} & = \rho x - y - xz \\ \dot{z} & = -\beta z + xy \end{aligned}$

    and

    HTML
    The solution is <span class="math">\(y = x^2 \hbox{ when x > 2}\)</span>

    will render as

    The solution is \(y = x^2 \hbox{ when x > 2}\)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder CodeProject
Canada Canada
Chris Maunder is the co-founder of CodeProject and ContentLab.com, and has been a prominent figure in the software development community for nearly 30 years. Hailing from Australia, Chris has a background in Mathematics, Astrophysics, Environmental Engineering and Defence Research. His programming endeavours span everything from FORTRAN on Super Computers, C++/MFC on Windows, through to to high-load .NET web applications and Python AI applications on everything from macOS to a Raspberry Pi. Chris is a full-stack developer who is as comfortable with SQL as he is with CSS.

In the late 1990s, he and his business partner David Cunningham recognized the need for a platform that would facilitate knowledge-sharing among developers, leading to the establishment of CodeProject.com in 1999. Chris's expertise in programming and his passion for fostering a collaborative environment have played a pivotal role in the success of CodeProject.com. Over the years, the website has grown into a vibrant community where programmers worldwide can connect, exchange ideas, and find solutions to coding challenges. Chris is a prolific contributor to the developer community through his articles and tutorials, and his latest passion project, CodeProject.AI.

In addition to his work with CodeProject.com, Chris co-founded ContentLab and DeveloperMedia, two projects focussed on helping companies make their Software Projects a success. Chris's roles included Product Development, Content Creation, Client Satisfaction and Systems Automation.

Comments and Discussions

 
QuestionWhat is the best way to tie the binding to the “preliminary” details? Pin
zampaa22-Sep-23 4:13
zampaa22-Sep-23 4:13 
QuestionWhat would be the best way to add an anchor to "pre" element? Pin
Sergey Alexandrovich Kryukov30-Jun-17 11:12
mvaSergey Alexandrovich Kryukov30-Jun-17 11:12 
AnswerRe: What would be the best way to add an anchor to "pre" element? Pin
Thomas Daniels3-Aug-17 21:44
mentorThomas Daniels3-Aug-17 21:44 
GeneralRe: What would be the best way to add an anchor to "pre" element? Pin
Sergey Alexandrovich Kryukov4-Aug-17 6:09
mvaSergey Alexandrovich Kryukov4-Aug-17 6:09 
GeneralRe: What would be the best way to add an anchor to "pre" element? Pin
Thomas Daniels4-Aug-17 6:19
mentorThomas Daniels4-Aug-17 6:19 
AnswerRe: What would be the best way to add an anchor to "pre" element? Pin
Sergey Alexandrovich Kryukov4-Aug-17 7:12
mvaSergey Alexandrovich Kryukov4-Aug-17 7:12 
Praise:) Pin
Member 1124779614-Jun-17 9:11
Member 1124779614-Jun-17 9:11 
QuestionHi. I'm still unable to type formulas in my articles using LaTeX script Pin
Arthur V. Ratz20-Jan-17 19:58
professionalArthur V. Ratz20-Jan-17 19:58 
QuestionHow I can highlight text? Pin
Martin Radu20-Dec-16 7:40
Martin Radu20-Dec-16 7:40 
AnswerRe: How I can highlight text? Pin
Sergey Alexandrovich Kryukov30-Jun-17 11:16
mvaSergey Alexandrovich Kryukov30-Jun-17 11:16 
QuestionAm I patently stupid or something. Pin
rerhart5857-Dec-16 1:26
rerhart5857-Dec-16 1:26 
GeneralMy vote of 5 Pin
Suvendu Shekhar Giri25-Jun-16 20:20
professionalSuvendu Shekhar Giri25-Jun-16 20:20 
QuestionIssues with Images Pin
Jitendra_Jain0423-Apr-15 4:30
Jitendra_Jain0423-Apr-15 4:30 
Hi
I have published an article with some images surprisingly We could see only text not the images
though I have uploaded all the images.


Please help ASAP. I am getting readers notifications about "No images"

Thanks
Jitendra Jain
GeneralMy vote of 5 Pin
Afzaal Ahmad Zeeshan2-Mar-15 9:21
professionalAfzaal Ahmad Zeeshan2-Mar-15 9:21 
QuestionGreat Tip Article Pin
Ryan Scott White1-Mar-15 18:26
professionalRyan Scott White1-Mar-15 18:26 
GeneralMy vote of 5 Pin
DrABELL26-Feb-15 17:07
DrABELL26-Feb-15 17:07 
GeneralRe: My vote of 5 Pin
thewazz2-Mar-15 7:17
professionalthewazz2-Mar-15 7:17 
GeneralRe: My vote of 5 Pin
thewazz2-Mar-15 7:20
professionalthewazz2-Mar-15 7:20 
GeneralRe: My vote of 5 Pin
Chris Maunder2-Mar-15 9:59
cofounderChris Maunder2-Mar-15 9:59 
GeneralRe: My vote of 5 Pin
DrABELL2-Mar-15 10:26
DrABELL2-Mar-15 10:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.