logo

G

  • Tutorials
  • API
  • Examples
  • Plugins
  • Productsantv logo arrow
  • 6.1.26
  • Canvas
    • Introduction
    • Options
    • Built-in objects
    • Coordinate system
    • Scenegraph & Lifecycle
    • Event
    • OffscreenCanvas & Server-side Rendering
    • CustomElementRegistry
    • Frequently Asked Questions
  • Renderer
    • Introduction
    • Canvas Renderer
    • Canvaskit Renderer
    • SVG Renderer
    • WebGL Renderer
    • WebGPU Renderer
    • Custom Renderer
  • Camera
    • Introduction
    • Camera Parameters
    • Camera action
    • Camera animation
  • Event
    • Introduction
    • Event Object
    • Gesture & Drag'n'Drop
    • Frequently Asked Questions
  • Animation
    • Web Animations API
    • Lottie
  • Basic Shapes
    • Basic Concepts
    • DisplayObject
    • Group
    • Text
    • Circle
    • Ellipse
    • Rect
    • Image
    • Line
    • Polygon
    • Polyline
    • Path
    • HTML
  • Style System
    • Introduction
    • CSS Typed OM
    • Inheritance
    • CSS Properties & Values API
    • CSS Layout API
    • Pattern
    • Gradient
  • 3D
    • 材质
    • 几何
    • Mesh
    • 光源
    • 雾
    • 交互
  • Built-in Objects
    • EventTarget
    • Node
    • Element
    • Document
    • MutationObserver
    • Utils
  • GPGPU
    • Introduction
    • Programming Model
    • Kernel API
    • Principles of classical GPGPU implementation
    • webgpu-graph
  • Declarative programming
    • 使用 Web Components
  • Devtools
    • G 开发者工具
    • 内置的渲染统计信息
    • 第三方开发调试工具

Inheritance

Previous
CSS Typed OM
Next
CSS Properties & Values API

Resource

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

In CSS, when no value is set for an attribute, the inheritable attribute will take the calculated value from the parent element.

https://developer.mozilla.org/zh-CN/docs/Web/CSS/inheritance

For example, the color property of CSS is inheritable, so for an <em> element that does not have this property set, it will use the value of the parent element, green.

p { color: green; }
<p>This paragraph has <em>emphasized text</em> in it.</p>

We have implemented a style system in G that also supports inheritance. For example, we create a Text without specifying fontSize or fontFamily properties, but it can still be rendered because it inherits the default style from the root node when added to the canvas: fontSize: '16px'; fontFamily: 'sans-serif'.

const text = new Text({
style: {
x: 100,
y: 100,
text: 'hello',
},
});
canvas.appendChild(text);

In this example, modifying the font size of the root node also affects the child elements, and with units like rem we can easily achieve an "elastic layout:"

canvas.document.documentElement.style.fontSize = `32px`;

The default style of root node

As with browsers, the default value (initial value) applies inheritable attributes at the root node.

For example, the browser default fontSize is 16px. We have styled root node in G as follows.

expect(documentElement.style.fill).to.equal('');
expect(documentElement.style.fillOpacity).to.equal('1');
expect(documentElement.style.fontFamily).to.equal('sans-serif');
expect(documentElement.style.fontSize).to.equal('16px');
expect(documentElement.style.fontStyle).to.equal('normal');
expect(documentElement.style.fontVariant).to.equal('normal');
expect(documentElement.style.fontWeight).to.equal('normal');
expect(documentElement.style.height).to.equal('');
expect(documentElement.style.lineCap).to.equal('butt');
expect(documentElement.style.lineDashOffset).to.equal('0');
expect(documentElement.style.lineJoin).to.equal('miter');
expect(documentElement.style.lineWidth).to.equal('1');
expect(documentElement.style.opacity).to.equal('');
expect(documentElement.style.stroke).to.equal('');
expect(documentElement.style.strokeOpacity).to.equal('1');
expect(documentElement.style.textTransform).to.equal('none');
expect(documentElement.style.textAlign).to.equal('start');
expect(documentElement.style.textBaseline).to.equal('alphabetic');
expect(documentElement.style.transformOrigin).to.equal('');
expect(documentElement.style.visibility).to.equal('visible');
expect(documentElement.style.pointerEvents).to.equal('auto');
expect(documentElement.style.width).to.equal('');
expect(documentElement.style.x).to.equal(0);
expect(documentElement.style.y).to.equal(0);
expect(documentElement.style.z).to.equal(0);
expect(documentElement.style.zIndex).to.equal(0);

Inherited properties supported

We currently support the following inheritable properties.

method nameinitial valueelementinheritableanimatablecomputed value
fillOpacity'1'allyesyes<number>
strokeOpacity'1'allyesyes<number>
lineWidth'1'allyesyes<length> <percentage>
lineJoin'miter'allyesno<keywords>
lineCap'butt'allyesno<keywords>
lineDash无allyesyes<array>
lineDashOffset'0'allyesyes<length> <percentage>
visibility'visible'allyesno<keywords>
pointerEvents'auto'allyesno<keywords>
fontSize'16px'allyesyes<length> <percentage>
fontFamily'sans-serif'allyesno<keywords>
fontStyle'normal'allyesno<keywords>
fontWeight'normal'allyesno<keywords>
fontVariant'normal'allyesno<keywords>
textBaseline'alphabetic'allyesno<keywords>
textAlign'start'allyesno<keywords>