Drupal 8 custom block with html and javascript
You need to use hook_theme() in your module, and declare a new Twig template that you want to use for your block.

Here's an example that needs to go to YOUR_MODULE.module file:

function YOUR_MODULE_theme() {
  return [
    'YOUR_TEMPLATE_KEY' =&gt; [
      // Here you can pass any variables you want, if necessary.
      'variables' =&gt; ['var1' =&gt; NULL],
    ],
  ];
}


Then create a folder called /templates in your custom module, and YOUR_TEMPLATE_KEY.html.twig file where you can have any markup you want. See below how to use the variables you pass to the template:

&lt;div id="your-block"&gt;
  {{ var1 }}
&lt;/div&gt;


Finally, to use it:

public function build() {
  return [
    '#theme' =&gt; 'YOUR_TEMPLATE_KEY',
    '#var1' =&gt; 'Variable one passed here',
  ];
}


Hope this helps.