style

package
v0.3.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TagOpen  = []byte("<style")
	TagClose = []byte("</style>")

	AttrType     = []byte(" type=\"")
	AttrMedia    = []byte(" media=\"")
	AttrNonce    = []byte(" nonce=\"")
	AttrTitle    = []byte(" title=\"")
	AttrBlocking = []byte(" blocking=\"")
)

Byte constants for HTML rendering.

Functions

func CSS

func CSS(css string) *element

CSS Creates a style element with CSS type explicitly set. Example: style.CSS("body { margin: 0; padding: 0; }") Renders: <style type="text/css">body { margin: 0; padding: 0; }</style>

func New

func New(nodes ...node.Node) *element

New Creates a new style element without any initial attributes. Example: style.New() Renders: <style></style>

func RawText

func RawText(content string) *element

RawText Creates a new style element with raw CSS content. Uses text.RawText which is not HTML-escaped. Preferred for dynamic inline stylesheets. Example: style.RawText("body { margin: 0; }") Renders: <style>body { margin: 0; }</style>

func RawTextf

func RawTextf(format string, args ...any) *element

RawTextf Creates a new style element with formatted raw CSS content. Uses text.RawTextf which is not HTML-escaped. Preferred for dynamic inline stylesheets with interpolation. Example: style.RawTextf(".%s { color: %s; }", className, colour) Renders: <style>.highlight { color: red; }</style>

func Static

func Static(content string) *element

Static Creates a new style element with static CSS content. Uses text.Static which is not HTML-escaped and is JIT-optimisable. Preferred for compile-time constant stylesheets. Example: style.Static("body { margin: 0; }") Renders: <style>body { margin: 0; }</style>

func Text

func Text(content string) *element

Text Creates a new style element with text content. Uses text.Text which HTML-escapes the output. Warning: HTML escaping will break CSS syntax (e.g., > in selectors). Use RawText, Static, or CSS instead. Example: style.Text("body { margin: 0; }") Renders: <style>body { margin: 0; }</style>

func Textf

func Textf(format string, args ...any) *element

Textf Creates a new style element with formatted text content. Uses text.Textf which HTML-escapes the output. Warning: HTML escaping will break CSS syntax. Use RawTextf instead. Example: style.Textf("%s { margin: %dpx; }", selector, margin) Renders: <style>body { margin: 8px; }</style>

Types

type Element

type Element = element

Element is an exported alias for the private element type

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL