HTML & CSS Core

I understand that in order to create a website we need html no matter the framework we use it'll eventually get compiled to html ok or not? just give me a single word

Yes

So how does browsers then understand html?

Browsers understand HTML through a rendering engine that parses the HTML document, constructs a Document Object Model (DOM) tree, and renders it visually on the screen.

Is this engine open source?

Some browser engines are open source, while others are not. For example:

Most modern browsers rely on open-source engines to foster collaboration and innovation.

Where can I find blink?

You can find Blink, the rendering engine used by Chromium-based browsers (like Google Chrome), in the open-source Chromium project. The source code is available at:

Chromium Git Repository

To explore Blink specifically, you can navigate to its subdirectory within the Chromium project:

Blink Source Code

This repository includes all the necessary code and documentation for Blink.

the links are borken

The output of this plugin was redacted.

Apologies for the earlier confusion. The links I provided were incorrect. You can access Blink's source code through the Chromium project. The correct URL is:

- Chromium Git Repository

Within this repository, Blink's source code is located in the third_party/blink/ directory.

For more information about Blink, you can visit the Blink documentation.

These resources provide access to Blink's source code and related documentation.

Give me an explanation on blink

Blink is an open-source browser rendering engine developed by Google as part of the Chromium project. It is responsible for interpreting and rendering HTML, CSS, and JavaScript to display web pages in a browser.

  1. HTML Parsing and DOM Construction: Blink parses HTML documents to construct the DOM (Document Object Model), a tree-like structure representing the webpage's content and structure.

  2. CSS Parsing and Style Calculation: It parses CSS files and inline styles, calculating how elements should be styled, including colors, sizes, fonts, and layout rules.

  3. Layout and Rendering: Blink determines the layout of each DOM element and renders it to the screen, handling tasks like text placement, images, and animations.

  4. JavaScript Execution: While JavaScript execution is primarily handled by V8, Google’s JavaScript engine, Blink collaborates closely with it to handle DOM manipulations and browser-specific APIs.

  5. Support for Web Standards: Blink implements web standards defined by organizations like the W3C (World Wide Web Consortium) and WHATWG (Web Hypertext Application Technology Working Group), ensuring interoperability across browsers.

Supported Browsers:

Blink powers several modern web browsers, including:

Contributions and Open-Source Nature:

Blink is designed to be highly performant, focusing on speed, efficiency, and adherence to modern web standards, making it one of the most widely used rendering engines in the world.

Are there any resources specially books on how to learn creating a browser engine?

Creating a browser engine is a complex task that requires knowledge in multiple domains like parsing, rendering, graphics, and networking. While there aren't many books specifically focused on "how to create a browser engine," there are resources that cover the foundational technologies and concepts you'll need. Here are some recommendations:


Books on Core Concepts

  1. Parsing and Compilers:

    • "Compilers: Principles, Techniques, and Tools" by Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman (The "Dragon Book").
    • "Modern Compiler Implementation in C/Java" by Andrew W. Appel.
  2. Rendering and Graphics:

    • "Computer Graphics: Principles and Practice" by John F. Hughes, Andries van Dam, et al.
    • "Real-Time Rendering" by Tomas Akenine-Möller, Eric Haines, and Naty Hoffman.
  3. Web Standards and Specifications:

  4. Operating Systems and Networking:

    • "Modern Operating Systems" by Andrew S. Tanenbaum.
    • "Computer Networking: A Top-Down Approach" by James F. Kurose and Keith W. Ross.

Online Tutorials and Resources

  1. Creating a Browser from Scratch:

    • Build Your Own Web Browser by Matt Brubeck. This is a series of blog posts walking through the creation of a simple browser engine.
  2. Open-Source Browser Projects:

    • Study the source code of open-source browsers like Chromium, Servo (Mozilla's experimental engine), or WebKit. These provide real-world implementations of browser engines.
  3. Browser Engineering Course:

    • Browser Engineering by Anthon Pang. This is an online textbook that provides a step-by-step guide to building a toy browser engine.
  4. Graphics Programming Tutorials:

    • Learn OpenGL for understanding rendering techniques that are often used in browser engines.

Hands-On Practice

  1. Start with a Toy Engine:

    • Use tutorials like Matt Brubeck's or Browser Engineering to build a simplified version of a browser engine.
  2. Contribute to Open Source:

    • Join projects like Chromium, Servo, or WebKit to gain firsthand experience working on a browser engine.
  3. Build Incrementally:

    • Start by creating a simple HTML parser.
    • Add CSS parsing and layout calculations.
    • Integrate JavaScript using an existing engine like V8 or SpiderMonkey.

Communities and Forums

With these resources, you can progressively develop the skills and knowledge to build a browser engine. Start small, and as you gain more understanding, tackle the more complex components.

What languages are mainly used for these engines?

Browser engines are typically developed using low-level, high-performance languages that allow fine-grained control over memory and CPU usage, as performance is a critical aspect of their functionality. Here are the most commonly used languages in browser engine development:


Main Languages

  1. C++:

    • Widely used in most browser engines due to its performance, portability, and control over system resources.
    • Examples:
      • Blink (Chromium-based browsers like Google Chrome)
      • WebKit (Safari)
      • Gecko (Firefox)
  2. Rust:

    • Gaining popularity for its memory safety features without sacrificing performance.
    • Example:
      • Servo (Mozilla's experimental browser engine, a precursor to some Rust features used in Gecko)
  3. C:

    • Used for low-level components and performance-critical parts of some engines.
    • Example:
      • Older parts of WebKit and other legacy components.

Supporting Languages

  1. JavaScript:

    • Used for testing, automation, and as the core scripting language interpreted by the engine.
  2. Python:

    • Often used in build systems, testing frameworks, and scripts for tasks like code generation.
  3. Objective-C/Swift:

    • For integrating browser engines with macOS and iOS applications (e.g., WebKit in Safari).
  4. Java:

    • Used in Android's WebView and Chromium implementations for mobile browsers.
  5. TypeScript/HTML/CSS:

    • For testing, UI prototyping, and user interface layers, especially in open-source projects.

Language Usage by Engine

Engine Primary Language(s) Supporting Language(s)
Blink C++, JavaScript Python, TypeScript
WebKit C++, Objective-C/Swift Python
Gecko C++, Rust Python, JavaScript
Servo Rust Python
EdgeHTML (legacy) C++, C Python

Why These Languages?

The choice of language depends on the goals of the engine, with C++ and Rust leading due to their balance of performance and control.

What about the css how does browsers understand CSS?

Browsers understand and process CSS through a series of steps as part of their rendering pipeline. Here’s a breakdown of how browsers handle CSS:


1. Parsing CSS

Example:
For the CSS:

body {
  background-color: lightblue;
}
h1 {
  color: darkblue;
}

The browser creates a CSSOM tree:

Stylesheet
├── body
│   └── background-color: lightblue
└── h1
    └── color: darkblue

2. Matching CSS Selectors


3. Combining DOM and CSSOM


4. Style Calculation


5. Layout and Painting


Tools to Explore CSS Processing


Behind the Scenes: Engine's Role

This process ensures that browsers accurately interpret CSS rules and render web pages as intended.

The browser engine handles CSS as well or there's a separate engine for this?

The browser engine handles CSS as part of its overall rendering pipeline. There isn’t a separate engine solely for CSS; instead, CSS processing is a specialized subsystem within the browser engine. Here’s how this integration works:


Components of a Browser Engine

A browser engine like Blink, WebKit, or Gecko is divided into multiple subsystems, each responsible for a part of the rendering process. These include:

  1. HTML Parser: Handles HTML and constructs the DOM.
  2. CSS Parser: Processes CSS and constructs the CSSOM.
  3. JavaScript Engine: Executes JavaScript code and manipulates the DOM and CSSOM.
  4. Layout Engine: Combines DOM and CSSOM into a render tree and calculates element positions.
  5. Painting and Compositing Engine: Draws the styled elements on the screen.

CSS Handling as Part of the Browser Engine

How CSS Integrates

  1. Parsing CSS: The browser engine's CSS parser turns raw CSS into a CSSOM.
  2. Selector Matching: The CSS subsystem matches styles to DOM elements.
  3. Style Computation: The CSS subsystem calculates the final style for each element.
  4. Interaction with JavaScript: JavaScript can dynamically modify CSS or DOM elements, and the CSS subsystem recalculates styles as needed.

Specialized Libraries within Engines

While the CSS subsystem is part of the browser engine, it often uses modular components:


Advantages of an Integrated System


Conclusion

The browser engine (e.g., Blink, Gecko) includes a CSS subsystem rather than relying on a separate engine. This integration ensures smooth coordination between styling, layout, and rendering.