Preview:
from yattag import Doc

import webbrowser

doc, tag, text = Doc().tagtext()

doc.asis('<!DOCTYPE html>')

with tag('html') as html:
    with tag('head') as head:
        with tag('title') as title:
            text('This is test web page')
    with tag('body') as body:
        with tag('h2') as h2:
            text('This is h2')

page = doc.getvalue()

f = open('page.html', 'w')
f.write(page)
f.close()

webbrowser.open('page.html')
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter