Bevy works well on the web! One of the things that took me some digging is how to get bevy to not create and inject a canvas element but instead use one that is already in the DOM. Below is a snippet of how to do this in rust as well as the corresponding HTML. Hopefully this saves someone some time!

I needed this in a prototype to see if I could get bevy and yew to work well together.

use bevy::prelude::*;

fn main() {
    App::new()
        .insert_resource(WindowDescriptor {
            #[cfg(target_arch = "wasm32")]
            canvas: Some("#bevy-portal".to_string()),
            ..default()
        })
        .add_plugins(DefaultPlugins)
        .run();
}
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
  </head>
  <body>
    <canvas
      id="bevy-portal"
      tabindex="0"
      data-raw-handle="1"
      alt="app"
      cursor="auto"
    ></canvas>
  </body>
</html>