Title: GTK CSS Properties Slug: css-properties

GTK supports CSS properties and shorthands as far as they can be applied in the context of widgets, and adds its own properties only when needed. All GTK-specific properties have a -gtk prefix.

Basic types

All properties support the following keywords: inherit, initial, unset, with the same meaning as defined in the CSS Cascading and Inheritance spec.

The following units are supported for basic datatypes:

Length : px, pt, em, ex, rem, pc, in, cm, mm, calc()

Percentage : %, calc()

Angle : deg, grad, turn, calc()

Time : s, ms, calc()

Length values with the em or ex units are resolved using the font size value, unless they occur in setting the font-size itself, in which case they are resolved using the inherited font size value.

The rem unit is resolved using the initial font size value, which is not quite the same as the CSS definition of rem.

The calc() notation adds considerable expressive power. There are limits on what types can be combined in such an expression (e.g. it does not make sense to add a number and a time). For the full details, see the CSS3 Values and Units spec.

A common pattern among shorthand properties (called ‘four sides’) is one where one to four values can be specified, to determine a value for each side of an area. In this case, the specified values are interpreted as follows:

4 values: : top right bottom left

3 values: : top horizontal bottom

2 values: : vertical horizontal

1 value: : all

Colors

GTK extends the CSS syntax with several additional ways to specify colors.

The first is a reference to a color defined via a @define-color rule in CSS. The syntax for @define-color rules is as follows:

@define-color Name Color

To refer to the color defined by a @define-color rule, prefix the name with @.

GTK also supports color expressions, which allow colors to be transformed to new ones. Color expressions can be nested, providing a rich language to define colors. Color expressions resemble functions, taking 1 or more colors and in some cases a number as arguments.

lighter(Color) : produces a brigher variant of Color

darker(Color) : produces a darker variant of Color

shade(Color, Number) : changes the lightness of Color. The number ranges from 0 for black to 2 for white.

alpha(Color, Number) : replaces the alpha value of color with number (between 0 and 1)

mix(Color1, Color2, Number) : interpolates between the two colors

Images

GTK extends the CSS syntax for images and also uses it for specifying icons. To load a themed icon, use

-gtk-icontheme(Name)

The specified icon name is used to look up a themed icon, while taking into account the values of the -gtk-icon-palette property. This kind of image is mainly used as value of the -gtk-icon-source property.

Symbolic icons from the icon theme are recolored according to the -gtk-icon-palette property, which defines a list of named colors. The recognized names for colors in symbolic icons are error, warning and success. The default palette maps these three names to symbolic colors with the names @error_color, @warning_color and @success_color respectively. The syntax for defining a custom palette is a comma-separated list of name-color pairs, e.g.

success blue, warning #fc3, error magenta

Recoloring is sometimes needed for images that are not part of an icon theme, and the

-gtk-recolor(uri, palette)

syntax makes this available. -gtk-recolor requires a url as first argument. The remaining arguments specify the color palette to use. If the palette is not explicitly specified, the current value of the -gtk-icon-palette property is used.

GTK supports scaled rendering on hi-resolution displays. This works best if images can specify normal and hi-resolution variants. From CSS, this can be done with

-gtk-scaled(Image1, Image2)

GTK CSS Properties

PropertyReferenceNotes
colorCSS Color Level 3
opacityCSS Color Level 3
filterCSS Filter Effect Level 1
font-familyCSS Fonts Level 3defaults to gtk-font-name setting
font-sizeCSS Fonts Level 3defaults to gtk-font-name setting
font-styleCSS Fonts Level 3
font-variantCSS Fonts Level 3only CSS2 values supported
font-weightCSS Fonts Level 3
font-stretchCSS Fonts Level 3
font-kerningCSS Fonts Level 3
font-variant-ligaturesCSS Fonts Level 3
font-variant-positionCSS Fonts Level 3
font-variant-capsCSS Fonts Level 3
font-variant-numericCSS Fonts Level 3
font-variant-alternatesCSS Fonts Level 3
font-variant-east-asianCSS Fonts Level 3
font-feature-settingsCSS Fonts Level 3
font-variation-settingsCSS Fonts Level 4
-gtk-dpiNumberdefaults to screen resolution
fontCSS Fonts Level 3CSS allows line-height, etc
font-variantCSS Fonts Level 3
caret-colorCSS Basic User Interface Level 3CSS allows an auto value
-gtk-secondary-caret-colorColorused for the secondary caret in bidirectional text
letter-spacingCSS Text Level 3
text-transformCSS Text Level 3CSS allows full-width and full-size-kana. Since 4.6
line-heightCSS Inline Layout Level 3Since 4.6
text-decoration-lineCSS Text Decoration Level 3
text-decoration-colorCSS Text Decoration Level 3
text-decoration-styleCSS Text Decoration Level 3CSS allows dashed and dotted
text-shadowCSS Text Decoration Level 3
text-decorationCSS Text Decoration Level 3
-gtk-icon-sourceImage, builtin or noneused for builtin icons in buttons and expanders
-gtk-icon-sizeLengthsize used for builtin icons in buttons and expanders
-gtk-icon-stylerequested, regular or symbolicpreferred style for application-loaded icons
-gtk-icon-transformTransform list or noneapplied to builtin and application-loaded icons
-gtk-icon-paletteColor palette, as explained aboveused to recolor symbolic icons
-gtk-icon-shadowShadow or noneapplied to builtin and application-loaded icons
-gtk-icon-filterFilter value list or noneapplied to builtin and application-loaded icons
transformCSS Transforms Level 1
transform-originCSS Transforms Level 1CSS allows specifying a z component
min-widthCSS Box Model Level 3CSS allows percentages
min-heightCSS Box Model Level 3CSS allows percentages
margin-topCSS Box Model Level 3CSS allows percentages or auto
margin-rightCSS Box Model Level 3CSS allows percentages or auto
margin-bottomCSS Box Model Level 3CSS allows percentages or auto
margin-leftCSS Box Model Level 3CSS allows percentages or auto
padding-topCSS Box Model Level 3CSS allows percentages
padding-rightCSS Box Model Level 3CSS allows percentages
padding-bottomCSS Box Model Level 3CSS allows percentages
padding-leftCSS Box Model Level 3CSS allows percentages
marginCSS Box Model Level 3a ‘four sides’ property
paddingCSS Box Model Level 3a ‘four sides’ property
border-top-widthCSS Backgrounds and Borders Level 3CSS allows other values
border-right-widthCSS Backgrounds and Borders Level 3CSS allows other values
border-bottom-widthCSS Backgrounds and Borders Level 3CSS allows other values
border-left-widthCSS Backgrounds and Borders Level 3CSS allows other values
border-top-styleCSS Backgrounds and Borders Level 3
border-right-styleCSS Backgrounds and Borders Level 3
border-bottom-styleCSS Backgrounds and Borders Level 3
border-left-styleCSS Backgrounds and Borders Level 3
border-top-right-radiusCSS Backgrounds and Borders Level 3
border-bottom-right-radiusCSS Backgrounds and Borders Level 3
border-bottom-left-radiusCSS Backgrounds and Borders Level 3
border-top-left-radiusCSS Backgrounds and Borders Level 3
border-top-colorCSS Backgrounds and Borders Level 3
border-right-colorCSS Backgrounds and Borders Level 3
border-bottom-colorCSS Backgrounds and Borders Level 3
border-left-colorCSS Backgrounds and Borders Level 3
border-image-sourceCSS Backgrounds and Borders Level 3
border-image-repeatCSS Backgrounds and Borders Level 3
border-image-sliceCSS Backgrounds and Borders Level 3a ‘four sides’ property
border-image-widthCSS Backgrounds and Borders Level 3a ‘four sides’ property
border-widthCSS Backgrounds and Borders Level 3a ‘four sides’ property
border-styleCSS Backgrounds and Borders Level 3a ‘four sides’ property
border-colorCSS Backgrounds and Borders Level 3a ‘four sides’ property
border-topCSS Backgrounds and Borders Level 3
border-rightCSS Backgrounds and Borders Level 3
border-bottomCSS Backgrounds and Borders Level 3
border-leftCSS Backgrounds and Borders Level 3
borderCSS Backgrounds and Borders Level 3
border-radiusCSS Backgrounds and Borders Level 3
border-imageCSS Backgrounds and Borders Level 3
outline-styleCSS Basic User Interface Level 3initial value is none, auto is not supported
outline-widthCSS Basic User Interface Level 3
outline-colorCSS Basic User Interface Level 3initial value is currentColor, invert is not supported
outline-offsetCSS Basic User Interface Level 3
outlineCSS Basic User Interface Level 3
background-colorCSS Backgrounds and Borders Level 3
background-clipCSS Backgrounds and Borders Level 3
background-originCSS Backgrounds and Borders Level 3
background-sizeCSS Backgrounds and Borders Level 3
background-positionCSS Backgrounds and Borders Level 3
background-repeatCSS Backgrounds and Borders Level 3
background-imageCSS Backgrounds and Borders Level 3not supported: urls without quotes
box-shadowCSS Backgrounds and Borders Level 3
background-blend-modeCSS Compositing and Blending Level 1only affects multiple backgrounds
backgroundCSS Backgrounds and Borders Level 3
transition-propertyCSS Transitions
transition-durationCSS Transitions
transition-timing-functionCSS Transitions
transition-delayCSS Transitions
transitionCSS Transitions
animation-nameCSS Animations Level 1
animation-durationCSS Animations Level 1
animation-timing-functionCSS Animations Level 1
animation-iteration-countCSS Animations Level 1
animation-directionCSS Animations Level 1
animation-play-stateCSS Animations Level 1
animation-delayCSS Animations Level 1
animation-fill-modeCSS Animations Level 1
animationCSS Animations Level 1
border-spacingCSS Table Level 3respected by GtkBoxLayout, GtkGridLayout, GtkCenterLayout