Click here to Skip to main content
Click here to Skip to main content

A Professional HTML Renderer You Will Use

, 29 Jan 2009 BSD
Rate this:
Please Sign up or sign in to vote.
100% managed code that draws HTML on any device

(See history for list of changes.) 



This is a library of 100% managed code that draws beautifully formatted HTML. It comes along with three WinForms controls:

  • HtmlPanel
  • HtmlLabel
  • HtmlTooltip

And a static method ready to draw HTML:

  • HtmlRenderer.Render(Graphics g, string html, RectangleF area, bool clip) 

Note: The drawing engine is based on the CSS Level 2 specification.


For years, I have been planning for a project like this. I prepared myself quite well. I went through the entire CSS Level 2 specification along with the HTML 4.01 specification.

One of the most interesting things I found is this: Drawing HTML is no more than laying out a bunch of boxes with borders margins and paddings. Once you overpass this paradigm, everything else is to help the code actually place the boxes on the right place, and then paint the string each box contains.

Imagine the power that drawing full-rich-formatted HTML on your controls can give to your applications. Use bold when you need it, italics on every message, and borders and fonts as you may like or need everywhere on the desktop application. One of the first projects where I will use it is on the tooltips of my Ribbon Project.

Although I have not tested it on mono yet, there should be no problem at all, since all of the code in the library is managed code and the methods it uses to paint are quite basic. It draws lines, rectangles, curves and text.

For now, the render looks really nice. Sometimes it can fool you to think you're using a real Web browser, trust me, download the demo, it is just an EXE and a DLL.

Using the Code

The library locates the code under the System.Drawing.Html namespace. The controls that render HTML are under the System.Windows.Forms namespace.

The renderer follows the CSS Box Model. Box model is nothing but a tree of boxes, just as the tree of HTML, each of these boxes is represented by a very used class called CssBox. The start node is represented by the class InitialContainer.

All the known CSS properties apply to each of these boxes. Each box may contain any number of child boxes and just one parent. The only box that has no parent at all is the so called Initial Container.

A typical use of an Initial Container to draw HTML would look like this:

//Create the InitialContainer
InitialContainer c = new InitialContainer("<html>");
//Give bounds to the container
//Measure bounds of each box on the tree

//Paint the HTML document


First a label, then a panel and at last a ToolTip, all of which support HTML rendering.

You may never use it, since I provided controls and methods that create this object for you.


A panel that is ready to accept HTML code via its Text property. Its full name is System.Windows.Forms.HtmlPanel.

The only properties you need to know are:

  • AutoScroll. Activates/Deactivates the auto-scroll capabilities as you know. It is set to true by default.
  • Text. Gets/Sets the HTML source.

The panel will update the bounds of the elements as you scroll or resize the control.


A label that is ready to accept HTML code via its Text property. Its full name is System.Windows.Forms.HtmlLabel.

The only properties you need to know are:

  • AutoScroll. Activates/Deactivates the auto-scroll capabilities as you know. It is set to true by default.
  • AutoSize. Sets the size of the label automatically if activated.
  • Text. Gets/Sets the HTML source.

Some interesting things:

  • The label will update the bounds of the elements as you scroll or resize the control.
  • The label can be transparent.
  • The panel has better performance than the label.


Works exactly like the ToolTip you already know, with the little difference that this tooltip will render HTML on it. It's full name is System.Windows.Forms.HtmlToolTip.

There are no properties here to learn. Use it just the way you use the ToolTip that comes with the framework. Internally, it just handles the OwnerDraw event.

Some Features of my Own

I took the liberty of adding a couple of features:

  • Background gradients
  • Rounded corners

These are achieved through the following CSS properties:

  • background-gradient: (color)
  • background-gradient-angle: (number)
  • corner-ne-radius: (length)
  • corner-nw-radius: (length)
  • corner-se-radius: (length)
  • corner-se-radius: (length)
  • corner-radius: (length){1,4} (shorthand for all corners)

What's Currently Supported by the Renderer?

  • Most border, padding and margin and positioning CSSproperties (except for the height property)
  • Text alignment horizontally and vertically, text indents too
  • Lists, ordered and unordered. Advanced numbering is not yet supported
  • Tables, almost all of it. Cell combinations work quite well as far as I tested them
  • Fonts (partially) and Colors
  • Backgrounds (just color)

Points of Interest

What can I say, this is one of the most fun projects I've ever been involved with. And so far, it runs beautifully and checks its original design goals.

I am planning to give it full rendering support, to the day that you may visualize a web page just as a good web browser would; and why not, make a WYSIWYG HTML editor to give amazing HTML editing power to your applications.

I'm also planning to make sure it runs perfectly well on Mono and on Mobile platforms.

In the next few days, I'll publish a list of supported HTML tags and CSS properties.


  • Jan 08 2009: First release
  • Jan 29 2009: Minor bugs fixed 
    • Text Encoding of samples
    • Large paragraphs and fonts because of Culture  
    • License 


This article, along with any associated source code and files, is licensed under The BSD License


About the Author

Jose Menendez Póo
Team Leader
Mexico Mexico
I'm in game programming now:
Jose Manuel Menéndez Poó
- I've been programming Windows and Web apps since 1997.
- My greatest concern nowadays is user interface usability.
Questions and stuff by twitter: @menendezpoo

Comments and Discussions

QuestionLife Saver PinmemberClutch23422-May-14 7:18 
AnswerRe: Life Saver Pinmemberthekingarthur1-Nov-14 3:59 
QuestionThis control is great! But there's an issue on CJK layout Pinmemberwmjordan12-Jul-13 21:53 
AnswerRe: This control is great! But there's an issue on CJK layout Pinmemberthekingarthur11-Sep-13 22:15 
GeneralRe: This control is great! But there's an issue on CJK layout Pinmemberwmjordan12-Sep-13 19:09 
GeneralMy vote of 5 PinmemberAmitosh S.M.10-Jul-13 21:31 
GeneralRe: My vote of 5 Pinmemberthekingarthur1-Nov-14 3:59 
GeneralMy vote of 5 Pinmemberpartha chakraborti1-Jul-13 5:48 
QuestionJavascript Pinmemberfilmee2424-Jun-13 21:27 
NewsThe project is actively developed on CodePlex! Pinmemberthekingarthur11-Mar-13 4:13 
GeneralRe: The project is actively developed on CodePlex! Pinmemberwmjordan19-Oct-13 4:44 
QuestionAdding CssBoxes Pinmembersolalem4-Mar-13 2:00 
GeneralMy vote of 5 Pinmemberkasatkin.aleksandr26-Feb-13 6:12 
Questionimg locking file Pinmembersvenvermeulen18-Feb-13 23:30 
QuestionWord wrap and width calculation PinmemberMRyndin26-Dec-12 2:53 
BugHi PinmemberYaseer Arafat24-Dec-12 14:05 
GeneralMy vote of 5 PinmemberYaseer Arafat21-Dec-12 12:47 
QuestionBR Tag not working. PinmemberMember 953116517-Nov-12 8:24 
AnswerRe: BR Tag not working. PinmemberJay Kappel20-Sep-13 14:42 
GeneralMy vote of 5 PinmemberSayan_dreams20-Sep-12 4:20 
QuestionCode path link in VB program Pinmembernbrege3-Aug-12 9:37 
QuestionNew version with height property? PinmemberSean Ortiz26-Jul-12 13:54 
QuestionProblem using HtmlToolTip with TreeView PinmembererSitzt27-Jun-12 0:45 
QuestionKudos to your work PinmemberThread30828-May-12 20:30 
AnswerRe: Kudos to your work PinmemberJose Menendez Póo29-May-12 4:43 
GeneralMy vote of 5 PinmemberProEnggSoft24-Feb-12 6:08 
GeneralMy vote of 5 Pinmembermanoj kumar choubey13-Feb-12 19:16 
GeneralMy vote of 5 Pinmemberring_026-Nov-11 3:12 
QuestionPossible to use it from an ASP.NET web site? Pinmemberboeledi7-Oct-11 15:07 
QuestionImage problem when using the renderer from VB PinmemberJohnny J.31-Aug-11 20:45 
AnswerRe: Image problem when using the renderer from VB PinmemberJohnny J.31-Aug-11 21:48 
GeneralRe: Image problem when using the renderer from VB PinmemberJohnny J.31-Aug-11 21:50 
My mistake - It DOES work! I just put "method:" instead of "property:" - silly me...
But still: I would prefer it if I could get it to work directly from VB...
Why can't I be applicable like John? - Me, April 2011
Beidh ceol, caint agus craic againn - Seán Bán Breathnach
Da mihi sis crustum Etruscum cum omnibus in eo!
Just because a thing is new don’t mean that it’s better - Will Rogers, September 4, 1932

QuestionQuestions ... PinmemberJerry Evans31-Jul-11 8:36 
GeneralMy vote of 4 PinmemberMarqW26-Jul-11 5:09 
GeneralRe: My vote of 4 PinmemberJohnny J.31-Aug-11 22:39 
QuestionRight To Left Pinmembermhmasoodi19-Jul-11 0:22 
BugLinks PinmemberAlan PSF18-Jul-11 9:13 
QuestionCopying Text PinmemberF.8.R17-Jul-11 14:46 
QuestionWhat Standard Are You Using for LineBreak Tag <br> PinmemberPeter Lee24-Jan-11 20:10 
QuestionMy 5, but... how about WPF port? PinmemberSAKryukov25-Dec-10 7:20 
GeneralBeyond all expectation. My 5+++ PinmemberSAKryukov25-Dec-10 7:19 
GeneralMy vote of 5 PinmemberVithidom7-Nov-10 12:37 
Ranttry to place google results to your renderer... Pinmember~Dim~9-Sep-10 22:42 
GeneralAnother control PinmemberChristopher Wells12-Aug-10 15:17 
GeneralVery nice Pinmembersha219110-Aug-10 22:41 
QuestionUpdate/ or add HTML5/CSS3 specification - perhaps HXTML Strict as well? PinmemberMember 243865319-Jul-10 3:07 
GeneralExcellent work PinmemberTotalQuazar17-Jun-10 7:31 
GeneralGreat stuff - but doesn't work with the FlowLayoutPanel control PinmemberSpankley6-Apr-10 6:29 
GeneralGreat work, compatibility issues, but great work so far PinmemberE D MacInnes10-Mar-10 7:19 
GeneralThis is fantastic PinmemberKo2 Hunter23-Feb-10 5:59 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141220.1 | Last Updated 30 Jan 2009
Article Copyright 2009 by Jose Menendez Póo
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid